package com.yehongyu.mytools.ui.applet;

//: Button2NewB.java
//An application and an applet
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Frame;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class Button2NewB extends Applet {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	Button b1 = new Button("Button 1"), b2 = new Button("Button 2");

	TextField t = new TextField(20);

	public void init() {
		b1.addActionListener(new B1());
		b2.addActionListener(new B2());
		add(b1);
		add(b2);
		add(t);
	}

	class B1 implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			t.setText("Button 1");
		}
	}

	class B2 implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			t.setText("Button 2");
		}
	}

//	// To close the application:
//	static class WL extends WindowAdapter {
//		public void windowClosing(WindowEvent e) {
//			System.exit(0);
//		}
//	}

	// A main() for the application:
	public static void main(String[] args) {
		Button2NewB applet = new Button2NewB();
		Frame aFrame = new Frame("Button2NewB");
		aFrame.addWindowListener(new WindowAdapter (){
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});
		aFrame.add(applet, BorderLayout.CENTER);
		aFrame.setSize(300, 200);
		applet.init();
		applet.start();
		aFrame.setVisible(true);
	}
} // /:~
